//
//  SetData.m
//  OST
//
//  Created by mac on 13-7-11.
//  Copyright (c) 2013年 mac. All rights reserved.
//

#import "LayerData.h"
#import "Common.h"

@interface LayerData ()

@end

@implementation LayerData

@synthesize resultData;

static LayerData *sharLayerDataInstance = nil;
+(LayerData *) sharedInstance
{
    if (!sharLayerDataInstance) {
        sharLayerDataInstance = [[LayerData alloc]init];
    }
    return sharLayerDataInstance;
}

- (void)requestFinished:(ASIHTTPRequest *)request
{
    NSArray *floorStrs= [reciveData componentsSeparatedByString:@"\n" ];
    NSMutableArray *result = [NSMutableArray array];
    for (NSString *floorStr in floorStrs) {
        NSArray *floors = [floorStr componentsSeparatedByString:@"/./"];
        NSMutableDictionary *dict = [NSMutableDictionary dictionary];
        [dict setValue:[floors objectAtIndex:0] forKey:@"alias"];
        [dict setValue:[floors objectAtIndex:1] forKey:@"floor"];
        if ([floors count]>4) {
            [dict setValue:[floors objectAtIndex:4] forKey:@"home"];
        }else{
            [dict setValue:@"" forKey:@"home"];
        }
        [result addObject:dict];
    }
    
    self.resultData = result;
    [self doneLoadData:resultData];
}


-(void)cleanData
{
    resultData=nil;
}

-(void)reLoadData
{
    self.httpRequest = [Common createHTTPRequest:@"cgi-bin/getDB.cgi?TN=FLOORDATA&R=0" delegate:self];
    [self.httpRequest startAsynchronous];
}

-(id)getResultData
{
    return resultData;
}



@end
